package top.wanzc.redisson.practise.example1;

import java.util.concurrent.TimeUnit;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

public class RedLock {
	
	public static void main(String[] args) {
		Config config = new Config();
		config.useSingleServer().setAddress("127.0.0.1:6379");
		config.useClusterServers().addNodeAddress("127.0.0.1:6379", "xiaocao1:6379");
		
		RedissonClient redissonClient = Redisson.create(config);
		RLock redLock = redissonClient.getLock("REDLOCK_KEY");
		boolean isLock;
		try {
			isLock = redLock.tryLock();
			isLock = redLock.tryLock(500, 10000, TimeUnit.MILLISECONDS);
			if (isLock) {
				System.out.println("get lock successfully.");
			}
		} catch (Exception e) {
			
		} finally {
			redLock.unlock();
		}
	}

}
